"use client"

import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import { Trash2, Star, StarOff, Download, X } from "lucide-react"
import { Contact } from "./columns"

interface BatchActionsBarProps {
  selectedContacts: Contact[]
  onBatchDelete: (contacts: Contact[]) => void
  onBatchToggleFavorite: (contacts: Contact[], isFavorite: boolean) => void
  onExport: (contacts: Contact[]) => void
  onClearSelection: () => void
}

export function BatchActionsBar({
  selectedContacts,
  onBatchDelete,
  onBatchToggleFavorite,
  onExport,
  onClearSelection
}: BatchActionsBarProps) {
  if (selectedContacts.length === 0) {
    return null
  }

  const favoriteCount = selectedContacts.filter(c => c.is_favorite).length
  const canAddToFavorite = favoriteCount < selectedContacts.length
  const canRemoveFromFavorite = favoriteCount > 0

  return (
    <div className="fixed bottom-4 left-1/2 transform -translate-x-1/2 z-50">
      <div className="bg-background border rounded-lg shadow-lg p-4 flex items-center gap-3">
        <Badge variant="secondary" className="px-3 py-1">
          已选择 {selectedContacts.length} 个联系人
        </Badge>
        
        <div className="flex items-center gap-2">
          {/* 添加到收藏 */}
          {canAddToFavorite && (
            <Button
              variant="outline"
              size="sm"
              onClick={() => onBatchToggleFavorite(selectedContacts, true)}
              className="h-8"
            >
              <Star className="h-4 w-4 mr-1" />
              添加到收藏
            </Button>
          )}
          
          {/* 取消收藏 */}
          {canRemoveFromFavorite && (
            <Button
              variant="outline"
              size="sm"
              onClick={() => onBatchToggleFavorite(selectedContacts, false)}
              className="h-8"
            >
              <StarOff className="h-4 w-4 mr-1" />
              取消收藏
            </Button>
          )}
          
          {/* 导出选中 */}
          <Button
            variant="outline"
            size="sm"
            onClick={() => onExport(selectedContacts)}
            className="h-8"
          >
            <Download className="h-4 w-4 mr-1" />
            导出选中
          </Button>
          
          {/* 批量删除 */}
          <Button
            variant="destructive"
            size="sm"
            onClick={() => onBatchDelete(selectedContacts)}
            className="h-8"
          >
            <Trash2 className="h-4 w-4 mr-1" />
            删除选中
          </Button>
        </div>
        
        {/* 清除选择 */}
        <Button
          variant="ghost"
          size="sm"
          onClick={onClearSelection}
          className="h-8 w-8 p-0"
        >
          <X className="h-4 w-4" />
        </Button>
      </div>
    </div>
  )
}
